import axios from 'axios'
import { message as antdMessage } from 'antd'

axios.interceptors.request.use((config) => {
  if(localStorage.getItem('token'))
    config.headers.Authorization = localStorage.getItem('token')
  return config
}, (error) => {
  return Promise.reject(error)
})


axios.interceptors.response.use((response) => {
  const {code, message } = response.data
  if(code === 200) {
    antdMessage.success(message)
  } else {
    antdMessage.error(message)
  }

  return response

}, (error) => {
  return Promise.reject(error)
})